
/* -----------------
* brief 
* 1. this is code gen by tools
*/

package service

import (
	"github.com/mjiulee/lego"
	"saas_sys_base/common"
)
import . "saas_sys_base/modules/user/models"

type TenantUserService struct {
    //继承
	UserService

	//
	webUserService WebUserService
	// add your model here
	tbTenantUser TenantUser
}


func (t* TenantUserService)ListTenantUser(keyword string,page,psize int) ([]map[string]string, int64, error) {
	// 业务查询
	queryMap := map[string]interface{}{
		"table":  map[string]string{"table": "tb_tenant_user", "alias": "t1"},
		"fields": []string{"t1.*"},
		"join": []map[string]string{
			// map[string]string{"table": "tb_xx as t2", "on": "t2.xid = t1.id"},
		},
		"where": []lego.QMapWhereField{
			//{"t1.if_del", "=", 0, "AND", false},
		},
		"search": map[string]string{
			//"t1.id": req.Keyword,
		},
		"orders": []string{"t1.id asc"},
		"page": map[string]int{
			"page":  page,
			"psize": psize,
		},
	}
	return lego.QueryListByMap(queryMap)
}

/* 根据id获取记录
 * -----------------
 */
func (t* TenantUserService) GetTenantUserById(id int64) *TenantUser {
	return t.tbTenantUser.RecodeById(id)
}

/* 添加
 * -----------------
 */
func (t* TenantUserService) SaveTenantUser(item2add *TenantUser) bool {
	return t.tbTenantUser.AddRecode(item2add)
}

/* 删除(硬删除)*/
func (t* TenantUserService) DelTenantUserById(id int64) bool {
	return t.tbTenantUser.DelRecodeById(id)
}

/* 更新
 * -----------------*/
func (t* TenantUserService) UpdateTenantUser(rc *TenantUser) bool {
	return t.tbTenantUser.UpdateRecode(rc)
}

//自定义函数
//创建一个平台租户账户
func (t* TenantUserService) CreateSysTenantUser(account string, password string) (user *LoginUser, tokenString string, err error) {
	whoAppTenant := common.Who{
		TenantId:0,
		MiniAppId:0,
		Uid:0,
	} //代表平台租户
	user, tokenString, err = t.webUserService.CreateAccount(whoAppTenant, account, password)

	return user, tokenString, err
}
